#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template import plot_template
from plot_template_combined import plot_template_combined

###############
## Plotting ###
###############
RatioSize=-0.2
RatioErr=1
RatioMin,RatioMax=0.5,1.5
RatioAdj=-1

ShowMCErr=1
MCErreeee=0.062
MCErreemm=0.052
MCErrmmee=0.052
MCErrmmmm=0.046
MCErr4l=0.052

plot_config='plot_configure'

histoDir='ZpT'

#ATLAS='ATLAS For Approval'
ATLAS=''
figFormat='all'

yscale=2

####### TrigMatch, MZ1
Xmin, Xmax=60, 120
Rebin=10
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_MZ1'
hxt='m_{Z1}^{eeee} [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_MZ1'
hxt='m_{Z1}^{ee#mu#mu} [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_MZ1'
hxt='m_{Z1}^{#mu#muee} [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_MZ1'
hxt='m_{Z1}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_MZ1'
hxt='m_{Z1} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### TrigMatch, MZ2
Xmin, Xmax=60, 120
Rebin=10
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_MZ2'
hxt='m_{Z2}^{eeee} [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_MZ2'
hxt='m_{Z2}^{ee#mu#mu} [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_MZ2'
hxt='m_{Z2}^{#mu#muee} [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_MZ2'
hxt='m_{Z2}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErrmmmm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_MZ2'
hxt='m_{Z2} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### TrigMatch, MZZ
Xmin, Xmax=100, 500
Rebin=20
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_MZZ'
hxt='m_{ZZ}^{eeee} [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_MZZ'
hxt='m_{ZZ}^{ee#mu#mu} [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_MZZ'
hxt='m_{ZZ}^{#mu#muee} [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_MZZ'
hxt='m_{ZZ}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErrmmmm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_MZZ'
hxt='m_{ZZ} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

